//
//  HMTabBarController.swift
//  SecondWB
//
//  Created by 赖建伟 on 16/11/26.
//  Copyright © 2016年 Itheima. All rights reserved.
//

import UIKit

class HMTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        addChildViewController()
        
        let tabBar = HMTabBar(frame: CGRect.init(x: 0, y: 0, width: kUIScreenWidth, height: 35))
        
        setValue(tabBar, forKey: "tabBar")
        
        tabBar.closure = {
            
            print("点击中间按钮")
            
        }
        
    }

   

    
    // MARK: - 添加子控制器
    func addChildViewController() {
        

        addChildViewController(HMHomeViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(HMMessageViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(HMFindViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(HMMineViewController(), title: "我", imageName: "tabbar_profile")

        
    }
    
    func addChildViewController(_ childController: UIViewController, title:String,imageName:String) {
        
        childController.title = title
        
        childController.tabBarItem.image = UIImage.init(named:imageName)
        childController.tabBarItem.selectedImage = UIImage.init(named: "\(imageName)_highlighted")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 13),NSForegroundColorAttributeName:UIColor.orange], for: UIControlState.selected)
        
        let nvc = UINavigationController(rootViewController: childController)
        
        addChildViewController(nvc)
        
        
    }
 

}
